package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Rect implements Comparable<Rect> {
    private int width;
    private int height;

    public Rect() {
    }

    public Rect(int width, int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public int compareTo(Rect o) {
        return this.width - o.width;
    }

    @Override
    public String toString() {
        return "Rect{" +
                "width=" + width +
                ", height=" + height +
                '}';
    }
}

public class CollectionSortDemo02 {
    public static void main(String[] args) {
        Rect r1 = new Rect(20,30);
        Rect r2 = new Rect(3,10);
        Rect r3 = new Rect(5,20);

        List<Rect> list = new ArrayList<>();
        list.add(r1);
        list.add(r2);
        list.add(r3);

        Collections.sort(list);
        System.out.println(list);

    }
}
